﻿using System;
using System.Collections;
using System.Configuration;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using KPIS.GERP.GBMS.BLL;
using KPIS.GERP.GBMS.IBLL;
using KPIS.GERP.GBMS.MODEL;
using Telerik.Web.UI;

namespace KPIS.GERP.GBMS.APP_UI
{
    public partial class SourceTypeCombo : System.Web.UI.UserControl
    {
        public RadComboBox ctrChild;
        private ISourceTypeBLL srcType = new SourceTypeBLL();
        private ISourceBLL src = new SourceBLL();

        protected void Page_Load(object sender, EventArgs e)
        {
        }

        public void LoadSourceTypeComboBox()
        {
            LoadSourceTypeComboBox(0);
        }

        public void LoadSourceTypeComboBox(int seq)
        {
            cbSourceType.DataSource = srcType.Search(seq, "", "", "");
            cbSourceType.DataBind();

            cbSourceType.Items.Insert(0, new RadComboBoxItem("- เลือกประเภทของเงิน -"));
        }

        protected void cbSourceType_SelectedIndexChanged(object o, EventArgs e)
        {
            //OnSourceTypeChange(e);

            int val = 0;

            if (cbSourceType.SelectedIndex > 0)
            {
                val = Convert.ToInt32(cbSourceType.SelectedValue);
                //SourceTypeChange(this, e);
                if (ctrChild != null)
                {
                    ctrChild.DataSource = src.Search(0, "", "", "", 0, val);
                    ctrChild.DataBind();

                    ctrChild.Items.Insert(0, new RadComboBoxItem("- เลือกแหล่งเงิน -"));
                    ctrChild.Focus();
                }
            }
        }

        protected void OnSourceTypeChange(EventArgs e)
        {
            //if (SourceTypeChange != null)
            //{
            //    if (cbSourceType.SelectedIndex > 0)
            //    {
            //        val = Convert.ToInt32(cbSourceType.SelectedValue);
            //        SourceTypeChange(this, e);

            //        cbChild.DataSource = src.Search(0, "", "", "", 0, val);
            //        cbChild.DataBind();
            //    }
            //}
        }
    }
}